package com.ptszyxx.popose.module.main.user.vm;

import android.app.Application;
import androidx.annotation.NonNull;

import com.ptszyxx.popose.module.main.gift.vm.GiftAndCallVM;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseListResponse;
import com.ysg.http.BaseResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessListResult;
import com.ysg.http.callback.OnSuccessResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.user.GuardEntity;
import com.ysg.http.data.entity.user.GuardResult;

import java.util.HashMap;
import java.util.Map;

public class UserGuardVM extends GiftAndCallVM {
    public String userId, txUserId;

    public UserGuardVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        public SingleLiveEvent onRefreshEvent = new SingleLiveEvent<>();
        public SingleLiveEvent onGuardEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onAvatarCommand = new BindingCommand(()-> jumpUserDetails());
    public BindingCommand onGuardCommand = new BindingCommand(()-> requestGuardSave());

    /**
     *
     */
    public void requestGuardList(){
        Map<String, String> map = new HashMap<>();
        map.put("beiUserId", userId);

        HttpUtils.getInstance()
                .list(model.guardList(map), this,
                        new OnSuccessListResult<GuardEntity>() {
                            @Override
                            public void onSuccessResult(BaseListResponse<GuardEntity> response) {
                                uc.onRefreshEvent.setValue(response.getData());
                            }
                        });
    }

    public void requestGuardSave(){
        Map<String, String> map = new HashMap<>();
        map.put("beiUserId", userId);

        HttpUtils.getInstance()
                .data(model.guardSave(map), this,
                        new OnSuccessResult<GuardResult>() {
                            @Override
                            public void onSuccessResult(BaseResponse<GuardResult> response) {
                                uc.onGuardEvent.setValue(response.getData());
                            }
                        });
    }

    private void jumpUserDetails() {
//        YActivityUtil.getInstance().jumpUserDetail(this, useId);
    }




}
